﻿using DLL.MSDM.Entity.Param;
using DLL.Standard.Infrastructure;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Serialization;

namespace DLL.NetStandard.FlushRobot.MS.Entity.Param
{
    [Serializable]
    public class CMS_WorkConfigParam : CNotifyPropertyChanged
    {
        //设备冲配模式，1：每只要都用新的溶媒，2：只抽取一次溶媒
        private int _FlushMode = 1;

        public int FlushMode
        {
            get { return _FlushMode; }
            set
            {
                if (_FlushMode != value)
                {
                    _FlushMode = value;
                    this.OnPropertyChanged();
                }
            }
        }

        //设备工作模式1：联机模式，2：单机模式，配置的参数都在配置文件当中，已医嘱号命名
        private int _WorkMode = 2;

        public int WorkMode
        {
            get { return _WorkMode; }
            set
            {
                if (_WorkMode != value)
                {
                    _WorkMode = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _enableJiFei = 0;

        public int EnableJiFei
        {
            get { return _enableJiFei; }
            set
            {
                if (_enableJiFei != value)
                {
                    _enableJiFei = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _enableSpeek = 0;

        public int EnableSpeek
        {
            get { return _enableSpeek; }
            set
            {
                if (_enableSpeek != value)
                {
                    _enableSpeek = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _BarCharCount = 20;   //条码个数

        public int BarCharCount
        {
            get { return _BarCharCount; }
            set
            {
                if (_BarCharCount != value)
                {
                    _BarCharCount = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _BarCharStartPos = 0;   //条码个数

        public int BarCharStartPos
        {
            get { return _BarCharStartPos; }
            set
            {
                if (_BarCharStartPos != value)
                {
                    _BarCharStartPos = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _SaveRecordToServer = 0;   //是否保存日志到服务器

        public int SaveRecordToServer
        {
            get { return _SaveRecordToServer; }
            set
            {
                if (_SaveRecordToServer != value)
                {
                    _SaveRecordToServer = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _SaveDataDays = 30;   //日志保留天数

        public int SaveDataDays
        {
            get { return _SaveDataDays; }
            set
            {
                if (_SaveDataDays != value)
                {
                    _SaveDataDays = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _putSolventFirst = 0;

        public int PutSolventFirst
        {
            get { return _putSolventFirst; }
            set
            {
                if (_putSolventFirst != value)
                {
                    _putSolventFirst = value;
                    this.OnPropertyChanged();
                }
            }
        }//是否先放溶媒

        private double _injcetBackDistance = 1.5;//注射器会打药液后回退的距离

        public double InjcetBackDistance
        {
            get { return _injcetBackDistance; }
            set
            {
                if (_injcetBackDistance != value)
                {
                    _injcetBackDistance = value;
                    this.OnPropertyChanged();
                }
            }
        }//是否先放溶媒

        //OpenjawDirect
        private int _OpenjawDirect = 0;

        public int OpenjawDirect
        {
            get { return _OpenjawDirect; }
            set
            {
                if (_OpenjawDirect != value)
                {
                    _OpenjawDirect = value;
                    this.OnPropertyChanged();
                }
            }
        }//是否先放溶媒

        //EnableDetection
        private int _EnableDetection = 0;

        public int EnableDetection
        {
            get { return _EnableDetection; }
            set
            {
                if (_EnableDetection != value)
                {
                    _EnableDetection = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _SolventEnableDetection = 0;

        public int SolventEnableDetection
        {
            get { return _SolventEnableDetection; }
            set
            {
                if (_SolventEnableDetection != value)
                {
                    _SolventEnableDetection = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _OpenjawMode = 0;

        public int OpenjawMode
        {
            get { return _OpenjawMode; }
            set
            {
                if (_OpenjawMode != value)
                {
                    _OpenjawMode = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _EnableSolventJaw = 1;

        public int EnableSolventJaw
        {
            get { return _EnableSolventJaw; }
            set
            {
                if (_EnableSolventJaw != value)
                {
                    _EnableSolventJaw = value;
                    this.OnPropertyChanged();
                }
            }
        }//溶媒夹抓启用标志位

        private int _EnableBottleJaw = 1;

        public int EnableBottleJaw
        {
            get { return _EnableBottleJaw; }
            set
            {
                if (_EnableBottleJaw != value)
                {
                    _EnableBottleJaw = value;
                    this.OnPropertyChanged();
                }
            }
        }//西林瓶夹抓启用标志位

        private int _EnableProcessBar = 0;

        public int EnableProcessBar
        {
            get { return _EnableProcessBar; }
            set
            {
                if (_EnableProcessBar != value)
                {
                    _EnableProcessBar = value;
                    this.OnPropertyChanged();
                }
            }
        }//西林瓶夹抓启用标志位

        private int _ProcessBarMethord = 0;

        public int ProcessBarMethord
        {
            get { return _ProcessBarMethord; }
            set
            {
                if (_ProcessBarMethord != value)
                {
                    _ProcessBarMethord = value;
                    this.OnPropertyChanged();
                }
            }
        }//西林瓶夹抓启用标志位

        private int _enableBatchDM = 0;//启用分批配药

        public int enableBatchDM
        {
            get { return _enableBatchDM; }
            set
            {
                if (_enableBatchDM != value)
                {
                    _enableBatchDM = value;
                    this.OnPropertyChanged();
                }
            }
        }

        //EnableAutoReset
        private int _enableAutoReset = 0;//启用登录自动复位

        public int EnableAutoReset
        {
            get { return _enableAutoReset; }
            set
            {
                if (_enableAutoReset != value)
                {
                    _enableAutoReset = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _enableBindingInjector = 1;//启用登录自动复位

        public int EnableBindingInjector
        {
            get { return _enableBindingInjector; }
            set
            {
                if (_enableBindingInjector != value)
                {
                    _enableBindingInjector = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _djClosePosIndex = 0;//放药夹爪默认打开方式

        public int djClosePosIndex
        {
            get { return _djClosePosIndex; }
            set
            {
                if (_djClosePosIndex != value)
                {
                    _djClosePosIndex = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _runningCloseLED = 0;//配药的时候关闭LED

        public int runningCloseLED
        {
            get { return _runningCloseLED; }
            set
            {
                if (_runningCloseLED != value)
                {
                    _runningCloseLED = value;
                    this.OnPropertyChanged();
                }
            }
        }

        private int _scanBarResultType = 0;//扫码返回状态种类，0，只有两种，1大于两种

        public int scanBarResultType
        {
            get { return _scanBarResultType; }
            set
            {
                if (_scanBarResultType != value)
                {
                    _scanBarResultType = value;
                    this.OnPropertyChanged();
                }
            }
        }
    }

    public class CMS_WR_WorkConfigParam : CNotifyPropertyChanged
    {
        private string folderPath = @"Param\";

        public CMS_WR_WorkConfigParam()
        {
            CWR_MotionCardType wrcard = new CWR_MotionCardType();
            CMotionCardType card = new CMotionCardType();
            int devType = 0;
            bool ret = wrcard.ReadParam();
            if (true == ret)
            {
                devType = wrcard.Obj.DeviceType;
            }
            else
            {
                devType = 0;
            }
            string deviceName = "";
            deviceName = CMotionCardType.DevTypeName[devType];
            string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
            folderPath = str_1 + @"Param\" + deviceName + @"\DeviceParam\";
        }

        private CMS_WorkConfigParam _Param = new CMS_WorkConfigParam();

        public CMS_WorkConfigParam Param
        {
            get { return _Param; }
            set
            {
                if (_Param != value)
                {
                    _Param = value;
                    OnPropertyChanged();
                }
            }
        }

        public bool ReadParam()
        {
            XmlSerializer xmlFormat = new XmlSerializer(typeof(CMS_WorkConfigParam));
            //string str2 = Application.StartupPath;
            string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
            string filePath = folderPath + "MS_WorkConfigParam.xml";
            if (File.Exists(filePath))
            {
                Stream fstream = File.OpenRead(filePath);
                _Param = (CMS_WorkConfigParam)xmlFormat.Deserialize(fstream);
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool SaveParam()
        {
            XmlSerializer xmlFormat = new XmlSerializer(typeof(CMS_WorkConfigParam));
            //现在将数据保存到本地的一个文件中
            string str_1 = System.AppDomain.CurrentDomain.BaseDirectory;
            string filePath = folderPath + "MS_WorkConfigParam.xml";

            Stream fstream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
            xmlFormat.Serialize(fstream, Param);
            fstream.Close();
            return true;
        }
    }
}